<template>
  <div>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      offset="50"
      @load="onLoad"
    >
    <!-- 房子列表 -->
      <house-item
        v-for="(item, index) in newList"
        :key="index"
        :list="item"
      ></house-item>
    </van-list>
  </div>
</template>

<script>
// 引入
import { houseAPI } from '@/api'
import HouseItem from './components/HouseItem'
export default {
  // 注册
  props: {
    city: String,
    houseList: {
      type: Array,
      default: () => []
    }
  },
  data () {
    return {
      houseListss: [],
      loading: false,
      refreshing: false,
      finished: false,
      page: 1 // 页码
    }
  },
  components: {
    HouseItem
  },
  created () {
    // console.log(this.city)
    // this.city = localStorage.getItem('city')
    this.getHouseList()
  },
  computed: {
    // 使用支持异步的计算属性来改变数据
    newList () {
      return this.houseList.length === 0 ? this.houseListss : this.houseList
    }
  },
  methods: {
    // 封装getHouseList方法用于接口请求
    async getHouseList () {
      const res = await houseAPI(this.cityInfo)
      console.log(res)
      this.houseListss = res.data.body.list
    },
    onLoad () {
      // 异步更新数据
      setTimeout(() => {
        // 加载状态结束
        this.loading = false

        // 数据全部加载完成
        // if (this.newList.length > 0) {
        //   this.getHouseList()
        // }
      }, 0)
    }
  }

}
</script>

<style>
</style>
